;;; packages --- Summary

;;; Commentary:
;;; marat.kagarmanov's Emacs settings

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(beacon-blink-delay 0.7)
 '(beacon-blink-duration 0.7)
 '(beacon-blink-when-focused t)
 '(beacon-mode t)
 '(blink-matching-paren nil)
 '(case-fold-search nil)
 '(column-number-mode t)
 '(cua-enable-cua-keys nil)
 '(cua-mode t nil (cua-base))
 '(cua-normal-cursor-color "black")
 '(explicit-shell-file-name "/bin/bash")
 '(global-auto-revert-mode t)
 '(indent-tabs-mode nil)
 '(initial-scratch-message ";;")
 '(line-number-display-limit-width 120)
 '(make-backup-files nil)
 '(neo-window-width 40)
 '(package-selected-packages
   (quote
    (go-gen-test kotlin-mode restclient rg vue-html-mode vue-mode gitlab gitlab-ci-mode go-dlv flycheck-golangci-lint emacsql-psql tern xref-js2 docker-compose-mode go-snippets go-tag merlin utop tuareg color-theme-modern color-theme-monokai env-var-import go-autocomplete go-complete yaml-mode web-mode web-completion-data use-package toml-mode smartparens sed-mode rainbow-delimiters pkgbuild-mode php-mode neotree monokai-theme markdown-mode js2-mode go-rename go-impl go-guru go-add-tags git-gutter focus-autosave-mode epm elscreen-fr dockerfile-mode cycbuf beacon auto-complete)))
 '(quote
   (cycbuf-dont-show-regexp
    (quote
     ("^ " "^*cycbuf*$" "^*.*$"))))
 '(recentf-exclude nil)
 '(recentf-max-saved-items 30)
 '(recentf-mode t)
 '(recentf-save-file "~/.emacs.d/.recentf")
 '(show-paren-mode t)
 '(size-indication-mode t)
 '(speedbar-show-unknown-files t)
 '(speedbar-update-flag nil)
 '(sql-product (quote postgres))
 '(tab-stop-list
   (quote
    (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76)))
 '(tab-width 4)
 '(tool-bar-mode nil)
 '(word-wrap nil))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "Hack" :foundry "simp" :slant normal :weight normal :height 100 :width normal))))
 '(cycbuf-current-face ((t (:background "dark slate gray" :weight bold)))))


;; Global Settings
(setq inhibit-startup-message t)    ;; skip start screen
(fset 'yes-or-no-p 'y-or-n-p)       ;; 'y' always enough for 'yes'
(setq auto-save-default nil)        ;; no autosave
(setq-default indent-tabs-mode nil) ;; indent with spaces by default (for html and others)
(ffap-bindings)                     ;; find-file-at-point ON
(font-lock-add-keywords 'go-mode    ;; coloring words like FIXME: or TODO: (currently for go-mode only)
                        '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
                           1 font-lock-warning-face t)))


;; Global key settings
(global-set-key [mode-line mouse-2] 'ignore)                   ;; disable middle clicking at mode-line
(global-set-key [?\C-x ?\z] 'ansi-term)                        ;; comfort shell
(global-set-key [?\M-g] 'goto-line)                            ;; goto line
(global-set-key [?\C-x ?\C-b] 'bs-show)                        ;; comfort buffer selector
(global-set-key [?\C-x ?\C-k] 'kill-some-buffers)              ;; mass buffer kill
(global-set-key (kbd "<M-next>") 'next-multiframe-window)      ;; Alt-PgUp to next frame window
(global-set-key (kbd "<M-prior>") 'previous-multiframe-window) ;; Alt-PgDn to previous frame window
(global-set-key [?\M-\;] 'comment-region)                      ;; shorcut for commenting selected text
(global-set-key [?\C-\;] 'uncomment-region)                    ;; shorcut for uncommenting selected text
;; duplicate line
(defun duplicate-line()
  (interactive)
  (move-beginning-of-line 1)
  (kill-line)
  (yank)
  (open-line 1)
  (next-line 1)
  (yank)
)
(global-set-key [?\C-x ?\C-d] 'duplicate-line)
;(global-set-key [kp-subtract] 'undo) ; [Undo]

;;; Packages
(add-to-list 'load-path (expand-file-name "~/.emacs.d/elpa")) ;; extension dir
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp")) ;; user-scripts dir
(load "package")
(require 'package)
;;(add-to-list 'package-archives
;;             '("melpa-stable" . "http://stable.melpa.org/packages/") t)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")
                         ("melpa" . "http://melpa.org/packages/"))) ;; breaks are made for cowards
(package-initialize)

;; autosave: on lost focus
(use-package focus-autosave-mode
  :config
  (focus-autosave-mode 1))

;; auto-complete replaced by go-autocomplete. Still usable if golang is off.
(use-package auto-complete
 :config
 (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
 (progn
   (ac-config-default)
   ;; to make completion only by TAB
   ;(setq ac-auto-start nil)
   ;(ac-set-trigger-key "TAB")
   (auto-complete-mode 1)))

;;color-theme
(use-package color-theme-monokai
  :ensure t
  :init
  (load-theme 'monokai t t)
  (enable-theme 'monokai))

;;beacon
(use-package beacon
  :ensure t
  :init
  (beacon-mode 1))

;; cycbuf
(use-package cycbuf
  :ensure t
  :config
  (global-set-key (kbd "C-x <down>") 'cycbuf-switch-to-previous-buffer) 
  (global-set-key (kbd "C-x <up>") 'cycbuf-switch-to-next-buffer))

;; elscreen-fr: replacement for 'elscreen' that using main emacs frame header for screens
(use-package elscreen-fr
  :config
  (elscreen-fr-start)
  ;; elscreen keys should be redefined after (elscreen-fr-start)
  (global-set-key (kbd "C-z SPC") 'elscreen-jump-0)
  (global-set-key (kbd "C-z <left>") 'elscreen-previous)
  (global-set-key (kbd "C-z <right>")  'elscreen-next))

;;go-mode
(use-package go-mode
  :ensure t
  :mode "\\.go\\'"
  :init
  (setq go-guess-gopath-functions (quote (go-plain-gopath)))
  :bind ("C-c C-r" . go-rename)
  :hook (before-save . gofmt-before-save))

(use-package flycheck-golangci-lint
  :ensure t
  :hook (go-mode . flycheck-golangci-lint-setup))

;; js2-mode
(use-package js2-mode
  :mode (("\\.js\\'" . js2-mode))
  ;; Better imenu
  :hook ((js-mode . js2-minor-mode)
         (js2-mode . js2-imenu-extras-mode)))

;;markdown-mode
(use-package markdown-mode
  :ensure t
  :mode (("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode)
         ("\\.text\\'" . markdown-mode)))

;; neotree
(use-package neotree
  :ensure t
  :init
  (global-set-key [f8] 'neotree-toggle)
  (global-set-key [f9] 'neotree-refresh))

;;rainbow-delimiters
(use-package rainbow-delimiters
  :ensure t
  :hook (prog-mode . rainbow-delimiters-mode))

;;smartparens
(use-package smartparens
  :ensure t
  :config
  (smartparens-global-mode 1))

;;tuareg
(use-package tuareg
  :ensure t
  :mode (("\\.ml[ily]?$" . tuareg-mode)
         ("\\.topml$" . tuareg-mode))
  :init
  (setq merlin-use-auto-complete-mode t) 
  (setq merlin-error-after-save nil)
  (setq opam-share (substring (shell-command-to-string "opam config var share") 0 -1))
  :hook ((tuareg-mode . tuareg-imenu-set-imenu)
         (tuareg-mode . merlin-mode)))

;; web-mode
(use-package web-mode
  :ensure t
  :mode (("\\.phtml\\'" . web-mode)
         ("\\.tpl\\.php\\'" . web-mode)
         ("\\.[agj]sp\\'" . web-mode)
         ("\\.as[cp]x\\'" . web-mode)
         ("\\.erb\\'" . web-mode)
         ("\\.mustache\\'" . web-mode)
         ("\\.djhtml\\'" . web-mode)
         ("\\.html?\\'" . web-mode)))

;;; .emacs ends here
